package sdfi.lee.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sdfi.lee.DAO.UserDAO;

/**
 * Servlet implementation class ChangeUserStatus
 */
public class ChangeUserStatus extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangeUserStatus() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String ustatus=request.getParameter("ustatus");
		String userid=request.getParameter("userid");
		String sql="update user set ustatus='"+ustatus+"' where id='"+userid+"'";
		String flag="{\"status\":\"error\"}";
		if(!(ustatus==null||userid==null))
		{
			try
			{
			if("success".equals(new UserDAO().updateUser(sql)))
			{
				flag="{\"status\":\"success\"}";
			}
			
			}
			catch(Exception ee)
			{
				ee.printStackTrace();
				
			}
		}
		PrintWriter pw=response.getWriter();
		pw.append(flag);
		pw.flush();
		pw.close();

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(request, response);
	}

}
